package com.gylang.sso.exception;

import com.gylang.common.model.VO.Result;
import com.gylang.sso.exception.domian.AuthException;
import com.gylang.sso.exception.domian.LoginException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author gylang,
 * @data 2019/11/16 9:26,
 * @DESC
 */
@RestControllerAdvice
public class GylangAuthExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handlerException(Exception e) {

        return Result.failure(-1, e.getMessage());
    }

    @ExceptionHandler(value = LoginException.class)
    @ResponseBody
    public Result handlerLoginException(LoginException e) {

        return Result.failure(e.getCode(), e.getMsg());
    }


    @ExceptionHandler(value = AuthException.class)
    @ResponseBody
    public Result handlerAuthException(AuthException e) {
        System.out.println("handlerAuthException");
        return Result.failure(e.getCode(), e.getMsg());
    }


}
